//
//  FLLTabBarController.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/1.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLTabBarController.h"
#import "FLLShopViewController.h"
#import "FLLHomeViewController.h"
#import "FLLCommunityViewController.h"
#import "FLLShikeViewController.h"
#import "FLLMineViewController.h"
#import "FLLMacro.h"
#import "FLLNavigationController.h"

@interface FLLTabBarController ()

@end

@implementation FLLTabBarController

#warning mark -- 注意(1)

+ (void)initialize {
    [UINavigationBar appearance];
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置
    
    // 设置tabBar上面item的文字的颜色和大小
    NSDictionary *attrbutes = @{NSForegroundColorAttributeName : [UIColor grayColor], NSFontAttributeName:[UIFont systemFontOfSize:12]};
    NSDictionary *selectedAttrbutes = @{NSForegroundColorAttributeName : [UIColor colorWithRed:0.95 green:0.35 blue:0.14 alpha:1.00], NSFontAttributeName:[UIFont systemFontOfSize:12]};
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:attrbutes forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrbutes forState:UIControlStateSelected];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //  创建一系列的ViewController和navigationController
    FLLHomeViewController *home = [[FLLHomeViewController alloc] init];
    [self setUpChildViewController:home title:@"食谱" image:[UIImage imageNamed:@"home_normal"] selectedImage:[UIImage imageNamed:@"home_select"]];
    
    FLLCommunityViewController *community = [[FLLCommunityViewController alloc] init];
    [self setUpChildViewController:community title:@"社区" image:[UIImage imageNamed:@"community_normal"] selectedImage:[UIImage imageNamed:@"community_select"]];
    
    FLLShopViewController *shop = [[FLLShopViewController alloc] init];
    [self setUpChildViewController:shop title:@"商城" image:[UIImage imageNamed:@"shop_normal"] selectedImage:[UIImage imageNamed:@"shop_select"]];
    
    FLLShikeViewController *shike = [[FLLShikeViewController alloc] init];
    [self setUpChildViewController:shike title:@"食课" image:[UIImage imageNamed:@"shike_normal"] selectedImage:[UIImage imageNamed:@"shike_select"]];
    
    FLLMineViewController *mine = [[FLLMineViewController alloc] init];
    [self setUpChildViewController:mine title:@"我的" image:[UIImage imageNamed:@"mine_normal"] selectedImage:[UIImage imageNamed:@"mine_select"]];
}

- (void)setUpChildViewController:(UIViewController *)viewController title:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
{
    viewController.navigationItem.title = title;
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = image;
    viewController.tabBarItem.selectedImage = selectedImage;
    FLLNavigationController *nav = [[FLLNavigationController alloc] initWithRootViewController:viewController];
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
